package com.dark.service.impl;

import com.dark.dao.mapper.UserMapper;
import com.dark.util.MD5Util;
import com.dark.util.RandomUtil;
import com.dark.util.SerialNumberUtil;
import com.dark.model.po.User;
import com.dark.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author chengluchao
 * @since 2022-09-23
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {


    /**
     * 初始磁盘大小*
     * 50G*
     */
    @Value("${jingjing.disk.default.size:5000000000}")
    private long defaultDiskSize;

    @Override
    @Transactional
    public void register(User user) {
        String uuid = RandomUtil.uuid();
        user.setUuid(uuid);
        user.setPwd(MD5Util.md5(user.getPwd(), user.getUuid()));
        user.setCode(SerialNumberUtil.generateDistributedIdString());
        user.setCreateUser(user.getAccount());
        user.setUpdateUser(user.getAccount());
        user.setUpdateTime(new Date());
        user.setCreateTime(new Date());
        save(user);
        this.doRegisterAfterSomeing(user);
    }

    @Override
    public String generatePassword(String pwd, String uuid) {
        return MD5Util.md5(pwd, uuid);
    }

    /**
     * 注册之后做的一些事情*
     *
     * @param user user
     */
    private void doRegisterAfterSomeing(User user) {

    }
}
